<?php
/**
 * Description of FE_Controller
 *
 * @author aquilax
 */
class FE_Controller extends Controller{

  protected $data = array();
  protected $controller_name;
  protected $action_name;
  protected $logged = FALSE;
  protected $uid = 0;

  public function __construct($sc = FALSE) {
    parent::__construct();
    $this->load_defaults();
    $this->data['content'] = '';

    //Debug
    $this->output->enable_profiler(TRUE);
  }

  protected function load_defaults() {
    /* FIXME: Fixed forum_id and forum_name*/
    $this->forum_id = 1;
    $this->data['forum_name'] = 'Forum name';

    //Langage
    $this->load->helper('language');

    //Handle User
    $this->load->model('user_model');
    $this->user_model->load();
    $this->logged = $this->user_model->logged();
    $this->data['logged'] = $this->logged;
    $this->user_id = $this->user_model->user_id();
    $this->data['user_id'] = $this->user_id;
    
    $this->data['title'] = 'Page title';
    $this->data['path'] = array();
    $this->controller_name = $this->router->fetch_directory() . $this->router->fetch_class();
    $this->action_name = $this->router->fetch_method();
  }

  protected function render($template = 'main') {
    $view_path = $this->controller_name . '/' . $this->action_name . '_tpl.php';
    if (file_exists(APPPATH . 'views/' . $view_path)) {
      $this->data['content'] .= $this->load->view($view_path, $this->data, true);
    }
    $this->load->view("layouts/".$template."_tpl.php", $this->data);
  }

}
?>
